// Copyright©,2020-2025
// Author: caocheng
// Version: 1.0.0
// Date: 2021/3/9 14:26
// Description：
package main

import (
	_ "gitee.com/chrischo/go-summer/example/router"
	SummerBoot "gitee.com/chrischo/go-summer/summer/summer-boot"
	SummerCore "gitee.com/chrischo/go-summer/summer/summer-core"
	SummerGin "gitee.com/chrischo/go-summer/summer/summer-gin"
	SummerStarter "gitee.com/chrischo/go-summer/summer/summer-starter"
	SummerWeb "gitee.com/chrischo/go-summer/summer/summer-web"
	"github.com/spf13/cast"
)

func init() {
	event := SummerStarter.NewWebServerStarter()
	SummerBoot.AddEvent(event)

	SummerBoot.AfterPrepare(func(ctx SummerCore.ApplicationContext) {
		container := SummerGin.NewContainer(SummerWeb.ContainerConfig{
			Port:      cast.ToInt(SummerBoot.GetIntProperty("web.server.port")),
			EnableSSL: SummerBoot.GetBoolProperty("web.server.ssl.enable"),
			KeyFile:   SummerBoot.GetStringProperty("web.server.ssl.key"),
			CertFile:  SummerBoot.GetStringProperty("web.server.ssl.cert"),
		})

		p := SummerWeb.NewGitSwagger("example")
		container.Swagger().Definitions = p.Swagger.Definitions
		event.WebServer.AddContainer(container)
	})
}

func main() {
	SummerBoot.ExpectSysProperties("GOPATH")
	configLocations := []string{
		"example/config/",
	}
	SummerBoot.NewApplication().Run(configLocations...)
}
